package com.dream52.pms.base;

import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Service
public interface MyService<T> {

	public Mapper<T> getMapper();

	public T getById(int key);

	public T getByWhere(String whereStr);

	public List<T> getListByWhere(String whereStr, String orderStr);

	public List<T> getPageListByWhere(String whereStr, int pageno, int pagesize, String orderStr);

	public PageInfo<T> getPageByWhere(String whereStr, int pageno, int pagesize, String orderStr);

	public int getCountByWhere(String whereStr);

	public int save(T entity);

	public int update(T entity);

	public int updateByWhere(T entity, String whereStr);

	public int deleteById(int key);

	public int deleteByWhere(String whereStr);

	/**
	 * 实体ID要加注解 @GeneratedValue(generator = "JDBC")
	 * 
	 * @param cacheId
	 * @param entity
	 * @return
	 */
	public int saveCache(String cacheId, T entity);

	public int saveCacheByUserid(String cacheId, T entity, int userid);

	public int updateCache(String cacheId, T entity);

	/** entity必须为完整数据 */
	public void updateCacheOnly(String cacheId, T entity);

	/** entity必须为完整数据 */
	public void updateCacheOnlyById(String cacheId, int id);

	/** entity必须为完整数据 */
	public void updateCacheByUserid(String cacheId, T entity, int userid);

	/** 只删缓存，不删库 */
	public void deleteCache(String cacheId, int id);

	/** 删缓存，删库 */
	public int deleteCacheById(String cacheId, int id);

	/** 删缓存，不删库 */
	public void deleteCacheAll(String cacheId);

	/** idsStr 用,分隔开，删缓存，不删库 */
	public void deleteCacheIds(String cacheId, String idsStr);

	/** 查找缓存值 */
	public T getCacheById(String cacheId, Integer key);

	/** 查找List缓存值 */
	public List<T> getCacheListByWhere(String cacheId, String whereStr, String orderStr);

	/** 根据where 更新数据库，并循环更新缓存 */
	public int updateCacheByWhere(String cacheId, T entity, String where);

	/** 根据where 不更新数据库，循环更新缓存 */
	public void updateCacheByWhereOnly(String cacheId, String where);
}
